SCREEN_WIDTH = 260
SCREEN_HEIGHT = 260
engine = {}

tmr = love.timer.getTime( )
clock = {}
clock.time = love.timer.getMicroTime( )
ohtList = {}

Font = love.graphics.newFont(  12 ) -- TODO: implement proper (jan)

function engine.paintGameelement(object)	
	if graphic.resourcesPO[object.name] then 
		local wtf = graphic.resourcesPO[object.name][1]
		local currentImage = graphic.resourcesPO[object.name][object.currentImage]
		local x =  object.center[1] - object.width/2
		local y =  object.center[2]  - object.height/2
		love.graphics.drawq( wtf, currentImage, x, y)
	else
		-- nothing sry ...
	end
	-- love.graphics.drawq( graphic.resourcesPO[object.name][1], graphic.resourcesPO[object.name][object.currentImage], object.center[1] - object.width/2, object.center[2]  - object.height/2)
   -- or animation 
end

function engine.paintPicture(_picture, _x, _y)
	love.graphics.draw(_picture, _x, _y)
end

function engine.paintText(_string, _x, _y)
	love.graphics.print(_string, _x, _y)
end

engine.clock = {}

function engine.clock.run()
	clock.time = love.timer.getTime( ) --TODO remove (jan)
	clock.hour = math.floor(clock.time/3600)
	clock.rest = clock.time % 3600
	clock.minut = math.floor(clock.time/60)
	clock.rest = clock.rest % 60
	clock.second = math.floor(clock.rest)
	clock.rest = clock.rest % 1
	clock.milli = clock.rest * 1000
	
	engine.clock.time = love.timer.getTime( )
	engine.clock.hour = math.floor(clock.time/3600)
	clock.rest = clock.time % 3600
	engine.clock.minut = math.floor(clock.time/60)
	clock.rest = clock.rest % 60
	engine.clock.second = math.floor(clock.rest)
	clock.rest = clock.rest % 1
	engine.clock.milli = clock.rest * 1000
	
end

function engine.paintOht()
	for i, v in pairs(ohtList) do
		if v.countDown:check() then
			love.graphics.print( text, v.x, v.y, 0, 0, 0 )
			v.y = v.y - v.speed
		else
			table.remove(ohtList, i)
		end
	end
end


controls = {}
controls.newPress = {}
controls.released = {}
controls.held = {}

function engine.controlsupdate() --TODO: complete
	--[[controls.released.button1 = Keys.released.A
	controls.released.button2 = Keys.released.B
	controls.released.button3 = Keys.released.X
	controls.released.button4 = Keys.released.Y
	controls.released.button5 = Keys.released.L
	controls.released.button6 = Keys.released.R
	controls.released.right = Keys.released.Right
	controls.released.left = Keys.released.Left
	controls.released.up = Keys.released.Up
	controls.released.down = Keys.released.Down
	controls.released.start = Keys.released.Start
	controls.released.select = Keys.released.Select
	controls.held.button1 = love.keyboard.isDown.A
	controls.held.button2 = love.keyboard.isDown.B
	controls.held.button3 = love.keyboard.isDown.X
	controls.held.button4 = love.keyboard.isDown.Y
	controls.held.button5 = love.keyboard.isDown.L
	controls.held.button6 = love.keyboard.isDown.R
	]]
	controls.held.right = love.keyboard.isDown("right")
	controls.held.left = love.keyboard.isDown("left")
	controls.held.up = love.keyboard.isDown("up")
	controls.held.down = love.keyboard.isDown("down")
	--controls.held.start = love.keyboard.isDown.Start
	--controls.held.select = love.keyboard.isDown.Select
	controls.newPress.button1 = love.keyboard.isDown("a")
	controls.newPress.button2 = love.keyboard.isDown("s")
	controls.newPress.button3 = love.keyboard.isDown("d")
	controls.newPress.button4 = love.keyboard.isDown("f")
	--controls.newPress.button5 = Keys.newPress.L
	--controls.newPress.button6 = Keys.newPress.R
	
	--[[controls.newPress.right = Keys.newPress.Right
	controls.newPress.left = Keys.newPress.Left
	controls.newPress.up = Keys.newPress.Up
	controls.newPress.down = Keys.newPress.Down
	controls.newPress.start = Keys.newPress.Start
	controls.newPress.select = Keys.newPress.Select
	]]
end

function engine.splitUpSprite(path, width, heigth) --returns an table containing the single pictures of an sprite
	tmpTable ={}
	image = love.graphics.newImage(path)
	table.insert(tmpTable, image)	
	imageWidth = image:getWidth()
	imageHeigth = image:getHeight()
	imageXAmoutn = imageWidth/width
	imageYAmount = imageHeigth/heigth
	for i = 0, imageXAmoutn  do
		for ii = 0, imageYAmount do
			table.insert(tmpTable, love.graphics.newQuad(i* width, ii* heigth, width, heigth, imageWidth, imageHeigth))
		end
	end
	return tmpTable
end

function engine.getWidthOfString(_string)
	return Font:getWidth(_string) -- TODO: font settings
end

function engine.getHeightOfString(_string)
	return Font:getHeight(_string) -- TODO: font settings
end

function engine.loadPicture( _path )
	return love.graphics.newImage( _path )
end

function engine.getWidthOfPicture(_picture)
	return _picture:getWidth()
end

function engine.getHeightOfPicture(_picture)
	return _picture:getHeight()
end

function engine.runOnceAnimations(dt)
	for _, a in ipairs(once_animations) do
		a[1]:update(dt)
	end
end
